﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using DICE_GS;

public class BuyTempSkillWindow : LTEventListenerC {
	public GameObject[] skillObject;
	public UILabel skillCostLabel;
	public GameObject selectedMark;

	public PvPMakeRoomSceneManager manager;

	List<CShopItem> itemList = new List<CShopItem>();
	// Use this for initialization
	void Start () {
		itemList = CShopItemDataManager.Instance.GetItemList(DICE_GS.SHOPTYPE.CHANCE_CARD);

		for(int i=0; i<(skillObject.Length<itemList.Count?4:skillObject.Length); i++)
		{
			Transform iconTrans = skillObject[i].transform.FindChild("IconSkill");
			if( iconTrans != null )
			{
				iconTrans.GetComponent<UISprite>().spriteName = itemList[i].icon_name;
			}
		}
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	void OnClickedBuyButton()
	{
		string[] split = itemList[selectedIndex].contents.Split(',');
		CSkillData skillData = CSkillDataManager.Instance.FindSkillData(split[1]);
		if( skillData != null )
		{
			CSceneManager.manager.SendSelectedTempSkill(skillData.id);
			manager.SetTempSkillInfo(skillData.id);
			gameObject.SetActive(false);
		}
	}

	void OnClickedCloseButton()
	{
		gameObject.SetActive(false);
	}

	int selectedIndex = -1;
	public override void OnEvent (int eventID)
	{
		base.OnEvent (eventID);

		selectedIndex = eventID;

		for(int i=0; i<skillObject.Length; i++)
		{
			if( i == eventID )
				skillObject[i].transform.localScale = new Vector3(1.25f, 1.25f, 1f);
			else
				skillObject[i].transform.localScale = Vector3.one;
		}

		selectedMark.transform.parent = skillObject[eventID].transform;
		selectedMark.transform.localPosition = new Vector3(39f,43,0f);
		skillCostLabel.text = itemList[eventID].price.ToString();
	}

	public void ReturnCallback(Hashtable returnData)
	{
	}
}
